#!/usr/bin/python
# -*- coding: UTF-8 -*-
# author: WuJian 2021-11-16
# desc: 公共资源定义

from ctypes import *

ECODE_OK = 0                   #OK
ECODE_OPEN = -1                #open error
ECODE_IOCTL = -2               #ioctl/fcntl error   
ECODE_INVAL = -3               #invalid parameter
ECODE_READ = -4                #read error    
ECODE_WRITE = -5               #write error
ECODE_THREAD = -6              #thread operate error
ECODE_PIPE = -7                #pipe operate error
ECODE_ERROR = -8               #generic error
ECODE_NO_DEV = -9              #no device   
ECODE_NOT_INIT = -10           #api not init
ECODE_DEV_BUSY = -11           #device is busy
ECODE_DUP_INIT = -12           #duplicate api init
ECODE_GPIO_ERROR = -13         #gpio operate error
ECODE_PWM_ERROR = -14          #pwm operate error    
ECODE_ADC_ERROR = -15          #adc operate error
ECODE_HWID_ERROR = -16         #hwid operate error
ECODE_SYSFS_ERROR = -17           #sysfs operate error    
ECODE_NO_INTERFACE_ERROR = -18     #usb0 dir is not existed
ECODE_DRV_NOT_AVAILABLE = -19      #device not available
ECODE_SOCKET_ERROR = -20
ECODE_IF_NOT_UP = -21
ECODE_CLOSE = -22               #close error
ECODE_ACC_START = -100
ECODE_AUDIO_START = -200
ECODE_AUDIO_SPEAKER_DISCONNECT_PVDD = -201                   # Output short to PVDD
ECODE_AUDIO_SPEAKER_DISCONNECT_GROUND = -202                 # Output short to Ground
ECODE_AUDIO_SPEAKER_DISCONNECT_OPEN_LOAD = -203              # Open load
ECODE_AUDIO_SPEAKER_DISCONNECT_SHORTED_LOAD = -204           # Shorted load
ECODE_AUDIO_SPEAKER_DISCONNECT_OPEN_FAIL = -205              # Open PA status file fail
ECODE_AUDIO_MIC_DISCONNECT = -250                            # MIC disconnect
ECODE_AUDIO_MIC_DISCONNECT_GROUND_OR_NO_START = -251         # MIC short to ground or the hd_audiocap_start api has not been executed yet         // MIC disconnect
ECODE_AUDIO_MIC_DISCONNECT_UNKNOWN = -252                    # MIC disconnect unknown reason
ECODE_AUDIO_SPEAKER_DISCONNECT = -253
ECODE_AUDIO_SPEAKER_DISCONNECT_RETRY_OVER = -254

ECODE_BTN_START = -300

ECODE_EMMC_START = -400
ECODE_EMMC_MOUNT_ERR = -401

ECODE_GNSS_START = -500

ECODE_GNSS_NO_DATA = -501

ECODE_GSENSOR_START = -600

ECODE_LCD_START = -700

ECODE_LED_START = -800
ECODE_LED_IRLED_DISCONNECT = -801      #ir-led is disconnected    
ECODE_LED_IRLED_OFF = -802             #ir-led is off, when diag the ir-led, it should be on
ECODE_LED_IRLED_VOLTAGE_FAIL = -803    #ir-led voltage error
ECODE_LED_IRLED_RETRY_FAIL = -804      #ir-led retry error
  
ECODE_LSENSOR_START = -900
ECODE_LSENSOR_DISABLE = -901

ECODE_THERMAL_START = -1000
ECODE_THERMAL_WARNING = -1001          #thermal high temperatur warning
ECODE_THERMAL_ABNORMAL = -1002          #thermal high temperatur abnormal

ECODE_TP_START = -1100
ECODE_TP_ABNORMAL = -1101              #touch panel device is abnormal
ECODE_TP_I2C_READ_ERROR = -1102        #read i2c register error
ECODE_TP_RESET = -1103                 #reset touch panel device
ECODE_TP_I2C_ERROR = -1104              #i2c of touch panel device error

ECODE_CAM_START = -1300         
ECODE_CAM_NOTDISCONNECT = -1301         #CAMERA sensor is not disconnected
ECODE_CAM_DISCONNECTFAIL = -1302         #CAMERA disconnection is abnormal
ECODE_CAM_I2C_TRANSFER_FAIL = -1303      #I2C transfer failure
ECODE_CAM_I2C_RETRY_OVER = -1304
ECODE_CAM_NO_SIGNAL = -1305

ECODE_FTP_PARAM   = -1400
ECODE_FTP_SERVER  = -1401
ECODE_FTP_FILE    = -1402
ECODE_FTP_LOGIN   = -1403 
ECODE_FTP_TRANS   = -1405

ECODE_USB_START = -1500
ECODE_USB_RESET_ERROR = -1501
ECODE_USB_SYS_REBOOT = -1502
ECODE_USB_HUB_RESET = -1503
ECODE_USB_OTHER_ERROR = -1504


ECODE_MAX   = -9999



BTN_ECALL = 59 #ECALL
BTN_CUSTOM = 60 #version <= 2 DISP  version > 2 CUSTOM
BTN_EVENT = 62 #EVNET
BTNERR = -1

BSP_OFF=0
BSP_ON=1






bspapi_fd = cdll.LoadLibrary('/usr/lib/libbspapi.so')

#######################GNSS API define start!#######################
gnss_drv_init=bspapi_fd.gnss_drv_init

gnss_drv_uinit=bspapi_fd.gnss_drv_uinit

gnss_drv_start = bspapi_fd.gnss_drv_start
DataCallBack  = CFUNCTYPE(None, POINTER(c_char), c_uint)
ErrorCallBack = CFUNCTYPE(None, c_int)
BTNDataCallBack  = CFUNCTYPE(None, c_uint, c_uint)

gnss_drv_stop=bspapi_fd.gnss_drv_stop

gnss_agps_info=bspapi_fd.gnss_agps_info

gnss_agps_data=bspapi_fd.gnss_agps_data

# baud
gnss_command_pvas01=bspapi_fd.gnss_command_pvas01
gnss_command_pvas01.argtypes=[c_int]

# upload interval 
gnss_command_pvas02=bspapi_fd.gnss_command_pvas02
gnss_command_pvas02.argtypes=[c_int]

# NMEA statement filter
gnss_command_pvas03=bspapi_fd.gnss_command_pvas03
gnss_command_pvas03.argtypes=[c_int, c_int, c_int, c_int, c_int, c_int, c_int, c_int]

# xing xi [1-7]
gnss_command_pvas04=bspapi_fd.gnss_command_pvas04
gnss_command_pvas04.argtypes=[c_int]

# start mode [0-3]
gnss_command_pvas10=bspapi_fd.gnss_command_pvas10
gnss_command_pvas10.argtypes=[c_int]

# revert week
gnss_set_gps_revert_week=bspapi_fd.gnss_set_gps_revert_week
#######################GNSS API define end!#######################

#######################Gsensor API define start!#######################
gsensor_drv_init=bspapi_fd.gsensor_drv_init
gsensor_drv_uinit=bspapi_fd.gsensor_drv_uinit
gsensor_drv_start=bspapi_fd.gsensor_drv_start
gsensor_drv_stop=bspapi_fd.gsensor_drv_stop
gsensor_drv_get_scale=bspapi_fd.gsensor_drv_get_scale
gsensor_drv_set_scale=bspapi_fd.gsensor_drv_set_scale
gsensor_drv_get_freq=bspapi_fd.gsensor_drv_get_freq
gsensor_drv_set_freq=bspapi_fd.gsensor_drv_set_freq

gsensor_drv_get_collision_sw_status=bspapi_fd.gsensor_drv_get_collision_sw_status
gsensor_drv_set_collision_sw_status=bspapi_fd.gsensor_drv_set_collision_sw_status
gsensor_drv_get_collision_threshold=bspapi_fd.gsensor_drv_get_collision_threshold
gsensor_drv_set_collision_threshold=bspapi_fd.gsensor_drv_set_collision_threshold

gsensor_drv_get_collision_flag=bspapi_fd.gsensor_drv_get_collision_flag 
gsensor_drv_clear_collision_flag=bspapi_fd.gsensor_drv_clear_collision_flag
gsensor_drv_reset=bspapi_fd.gsensor_drv_reset
#######################Gsensor API define end!#######################

####################### ACC API define start!#######################
acc_drv_init=bspapi_fd.acc_drv_init

acc_drv_start=bspapi_fd.acc_drv_start
AccCallBack  = CFUNCTYPE(None, c_int)

acc_drv_get_status=bspapi_fd.acc_drv_get_status

acc_drv_stop=bspapi_fd.acc_drv_stop

acc_drv_uinit=bspapi_fd.acc_drv_uinit
####################### ACC API define end!#######################

####################### buttion API define start!#######################
btn_drv_init=bspapi_fd.btn_drv_init

btn_drv_start=bspapi_fd.btn_drv_start
BtnCallBack  = CFUNCTYPE(None, c_int, c_int)

btn_drv_get_status=bspapi_fd.btn_drv_get_status

btn_drv_stop=bspapi_fd.btn_drv_stop

btn_drv_uinit=bspapi_fd.btn_drv_uinit
####################### buttion API define end!#######################

#######################TP API define start!#######################
tp_drv_init = bspapi_fd.tp_drv_init
tp_drv_uinit = bspapi_fd.tp_drv_uinit
tp_drv_start = bspapi_fd.tp_drv_start
tp_drv_stop = bspapi_fd.tp_drv_stop
tpi2c_drv_diag = bspapi_fd.tpi2c_drv_diag
tp_drv_diag = bspapi_fd.tp_drv_diag
tp_drv_reset = bspapi_fd.tp_drv_reset
#######################TP API define start!#######################
#emmc
#######################EMMC API define start!#######################
emmc_get_health_report = bspapi_fd.emmc_get_health_report
emmc_get_active_ptn = bspapi_fd.emmc_get_active_ptn
file_write_int = bspapi_fd.file_write_int
emmc_mount = bspapi_fd.emmc_mount
emmc_check_ptn = bspapi_fd.emmc_check_ptn
#######################EMMC API define start!#######################

#######################cam API define start!#######################
cam_drv_init = bspapi_fd.cam_drv_init
cam_drv_uinit = bspapi_fd.cam_drv_uinit
cam_drv_diag =  bspapi_fd.cam_drv_diag
i2c_drv_diag = bspapi_fd.i2c_drv_diag
cam_drv_reset = bspapi_fd.cam_drv_reset

#######################thermal API define start!#######################
get_thermal_temp = bspapi_fd.get_thermal_temp
get_cpu_thermal_temp = bspapi_fd.get_cpu_thermal_temp
thermal_drv_init = bspapi_fd.thermal_drv_init
thermal_drv_uinit = bspapi_fd.thermal_drv_uinit
thermal_drv_diag = bspapi_fd.thermal_drv_diag
thermal_drv_fan_ctrl=bspapi_fd.thermal_drv_fan_ctrl
fan_power_on=bspapi_fd.fan_power_on
fan_power_off=bspapi_fd.fan_power_off
#######################thermal API define end!#######################

####################### FTP API define start!#####################
ftp_drv_get=bspapi_fd.ftp_drv_get
ftp_drv_put=bspapi_fd.ftp_drv_put
ftp_drv_put_mdm=bspapi_fd.ftp_drv_put_mdm
ftp_drv_get_mdm=bspapi_fd.ftp_drv_get_mdm
####################### FTP API define end!#######################


####################### lsensor selftest define start!#####################

lsensor_drv_init=bspapi_fd.lsensor_drv_init
lsensor_drv_uinit=bspapi_fd.lsensor_drv_uinit
lsensor_drv_get_status=bspapi_fd.lsensor_drv_get_status
lsensor_drv_set_status=bspapi_fd.lsensor_drv_set_status
lsensor_drv_get_timing=bspapi_fd.lsensor_drv_get_timing
lsensor_drv_set_timing=bspapi_fd.lsensor_drv_set_timing
lsensor_drv_get_gain=bspapi_fd.lsensor_drv_get_gain
lsensor_drv_set_gain=bspapi_fd.lsensor_drv_set_gain
lsensor_drv_get_low_threshold=bspapi_fd.lsensor_drv_get_low_threshold
lsensor_drv_set_low_threshold=bspapi_fd.lsensor_drv_set_low_threshold
lsensor_drv_get_high_threshold=bspapi_fd.lsensor_drv_get_high_threshold
lsensor_drv_set_high_threshold=bspapi_fd.lsensor_drv_set_high_threshold
lsensor_drv_get_current_data=bspapi_fd.lsensor_drv_get_current_data
lsensor_drv_get_als=bspapi_fd.lsensor_drv_get_als
lsensor_drv_start=bspapi_fd.lsensor_drv_start
lsensor_drv_stop=bspapi_fd.lsensor_drv_stop
####################### lsensor selftest end!#######################
####################### LED API define start!#####################
leds_init=bspapi_fd.leds_init
led_get_status=bspapi_fd.led_get_status
led_get_status2=bspapi_fd.led_get_status2
led_set_status=bspapi_fd.led_set_status
led_set_status2=bspapi_fd.led_set_status2
ecall_led_set_status=bspapi_fd.ecall_led_set_status
ecall_led_get_status=bspapi_fd.ecall_led_get_status
ecall_led_set_status2=bspapi_fd.ecall_led_set_status2
ecall_led_get_status2=bspapi_fd.ecall_led_get_status2
ir_led_get_status=bspapi_fd.ir_led_get_status
ir_led_set_status=bspapi_fd.ir_led_set_status
ir_led_diag=bspapi_fd.ir_led_diag
leds_uinit=bspapi_fd.leds_uinit
ir_led_power=bspapi_fd.ir_led_power
####################### LED API define end!#######################

####################### lcd selftest define start!#####################
lcd_drv_init=bspapi_fd.lcd_drv_init
lcd_drv_backlight_control=bspapi_fd.lcd_drv_backlight_control
lcd_drv_uinit=bspapi_fd.lcd_drv_uinit
####################### lcd selftest define end!#####################

####################### AUDIO API define start!#####################
audio_drv_init = bspapi_fd.audio_drv_init
audio_drv_speaker_diag = bspapi_fd.audio_drv_speaker_diag
audio_drv_mic_diag = bspapi_fd.audio_drv_mic_diag
audio_drv_channel_set = bspapi_fd.audio_drv_channel_set
audio_drv_channel_get = bspapi_fd.audio_drv_channel_get
audio_drv_pa_mute = bspapi_fd.audio_drv_pa_mute

audio_drv_get_mute = bspapi_fd.audio_drv_get_mute
audio_drv_uinit = bspapi_fd.audio_drv_uinit

####################### AUDIO API define end!#######################

